#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
typedef char datatype;

typedef struct TreeNode {
    struct TreeNode* left;
    struct TreeNode* right;
    datatype val;
}TreeNode;

void TreeCreate(TreeNode* node, datatype* data, int* pi)
{
    if (data[*pi] == '#')
    {
        free(node);
        node = NULL;
        (*pi)++;
    }
    node->val = data[(*pi)++];
    node->left = NULL;
    node->right = NULL;
    if (data[(*pi)] != '#')
    {
        node->left = malloc(sizeof(TreeNode));
        TreeCreate(node->left, data, pi);
    }
    (*pi)++;
    if (data[(*pi)] != '#')
    {
        node->right = malloc(sizeof(TreeNode));
        TreeCreate(node->right, data, pi);
    }
}

void InOrder(TreeNode* node)
{
    if (node == NULL)
        return;
    InOrder(node->left);
    printf("%c ", node->val);
    InOrder(node->right);
}

int main() {


    datatype arr[101] = { 0 };


    while (scanf("%s", arr) != EOF)
    {
        int i = 0;
        TreeNode* node = malloc(sizeof(TreeNode));
        TreeCreate(node, arr, &i);
        InOrder(node);
        printf("\n");
    }
    return 0;
}